import base64

import pytesseract
from PIL import Image

"""base64信息转图片与图片转base64"""


def base64_to_img(byte_str, file_path):
    imgdata = base64.b64decode(byte_str)
    with open(file_path, 'wb') as f:
        f.write(imgdata)


def base64_to_str(byte_str):
    return base64.b64encode(byte_str.encode("utf-8")).decode('utf-8')


def base64_to_text(file_path):
    return pytesseract.image_to_string(Image.open(file_path))


if __name__ == '__main__':
    data = ""

    base64_to_img(data.split(",")[1], "../../image/origina388l.png")
